import { defineStore } from 'pinia'

export const useCountStore = defineStore('count', {
    //actions 里面放置的是一个一个的方法，用于响应组件中的动作
    actions: {
        increment(value: number) {
            console.log('increment 被调用了', value)
            //this 是当前的 store
            console.log(this.sum)
            this.sum += value
            this.school = '福大'
            this.address = '福州'
        }
    },
    //state 叫状态，也叫做数据
    //真正存储数据的地方
    state() {
        return {
            sum: 6,
            school: 'Fuzhou University',
            address: 'Fuzhou'
        }
    },
    //这两种写法一样的
    getters: {
        bigSum(): number {
            return this.sum * 10
        },
        bigSchool(state) {
            return state.school.toUpperCase()
        }
    }
})